# Copyright 2021 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")

package(default_visibility = ["//visibility:public"])

py_library(
    name = "jnp_testbase",
    srcs = ["jnp_testbase.py"],
    deps = [
        "//spu:api",
        "//spu/utils:simulation",
    ],
)

py_library(
    name = "utils",
    srcs = ["utils.py"],
    deps = [
        "//spu:api",
    ],
)

py_binary(
    name = "np_op_status",
    srcs = ["np_op_status.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_aby3_r128_test",
    timeout = "long",
    srcs = ["jnp_aby3_r128_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_aby3_r128_test_x64",
    timeout = "long",
    srcs = ["jnp_aby3_r128_test.py"],
    env = {
        "ENABLE_X64_TEST": "1",
    },
    main = "jnp_aby3_r128_test.py",
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_aby3_r64_test",
    timeout = "long",
    srcs = ["jnp_aby3_r64_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_aby3_r64_test_x64",
    timeout = "long",
    srcs = ["jnp_aby3_r64_test.py"],
    env = {
        "ENABLE_X64_TEST": "1",
    },
    main = "jnp_aby3_r64_test.py",
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_cheetah_r64_test",
    size = "enormous",
    srcs = ["jnp_cheetah_r64_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_cheetah_r64_test_x64",
    size = "enormous",
    srcs = ["jnp_cheetah_r64_test.py"],
    env = {
        "ENABLE_X64_TEST": "1",
    },
    main = "jnp_cheetah_r64_test.py",
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_semi2k_r128_test",
    timeout = "long",
    srcs = ["jnp_semi2k_r128_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_semi2k_r128_test_x64",
    timeout = "long",
    srcs = ["jnp_semi2k_r128_test.py"],
    env = {
        "ENABLE_X64_TEST": "1",
    },
    main = "jnp_semi2k_r128_test.py",
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_semi2k_r64_test",
    timeout = "long",
    srcs = ["jnp_semi2k_r64_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_semi2k_r64_test_x64",
    timeout = "long",
    srcs = ["jnp_semi2k_r64_test.py"],
    env = {
        "ENABLE_X64_TEST": "1",
    },
    main = "jnp_semi2k_r64_test.py",
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_ref2k_r64_test",
    timeout = "long",
    srcs = ["jnp_ref2k_r64_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "jnp_ref2k_r64_test_x64",
    timeout = "long",
    srcs = ["jnp_ref2k_r64_test.py"],
    env = {
        "ENABLE_X64_TEST": "1",
    },
    main = "jnp_ref2k_r64_test.py",
    deps = [
        ":jnp_testbase",
    ],
)

py_binary(
    name = "jnp_debug",
    srcs = ["jnp_debug.py"],
    deps = [
        "//spu:api",
        "//spu/utils:simulation",
    ],
)

py_test(
    name = "spu_compiler_test",
    srcs = ["spu_compiler_test.py"],
    deps = [
        "//spu:api",
        "//spu/utils:frontend",
        "//spu/utils:simulation",
    ],
)

py_test(
    name = "jax_sanity_test",
    srcs = ["jax_sanity_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)

py_test(
    name = "spu_runtime_test",
    srcs = ["spu_runtime_test.py"],
    deps = [
        "//spu:api",
        "//spu/utils:simulation",
    ],
)

py_test(
    name = "spu_io_test",
    srcs = ["spu_io_test.py"],
    deps = [
        "//spu:api",
        "//spu/utils:simulation",
    ],
)

py_test(
    name = "link_test",
    srcs = ["link_test.py"],
    deps = [
        ":utils",
        "//spu:api",
    ],
)

py_test(
    name = "legacy_psi_test",
    srcs = ["legacy_psi_test.py"],
    data = [
        "//spu/tests/data",
    ],
    flaky = True,
    tags = [
        "exclusive-if-local",
    ],
    deps = [
        ":utils",
        "//spu:psi",
        "//spu/utils:simulation",
    ],
)

py_test(
    name = "psi_test",
    srcs = ["psi_test.py"],
    data = [
        "//spu/tests/data",
    ],
    flaky = True,
    tags = [
        "exclusive-if-local",
    ],
    deps = [
        ":utils",
        "//spu:psi",
    ],
)

py_test(
    name = "ub_psi_test",
    srcs = ["ub_psi_test.py"],
    data = [
        "//spu/tests/data",
    ],
    flaky = True,
    tags = [
        "exclusive-if-local",
    ],
    deps = [
        ":utils",
        "//spu:psi",
    ],
)

py_test(
    name = "pir_test",
    srcs = ["pir_test.py"],
    data = [
        "//spu/tests/data",
    ],
    flaky = True,
    tags = [
        "exclusive-if-local",
    ],
    deps = [
        ":utils",
        "//spu:psi",
    ],
)

py_test(
    name = "frontend_test",
    srcs = ["frontend_test.py"],
    deps = [
        "//spu/utils:frontend",
    ],
)

py_test(
    name = "distributed_test",
    timeout = "short",
    srcs = ["distributed_test.py"],
    flaky = True,
    tags = [
        "exclusive-if-local",
    ],
    deps = [
        ":utils",
        "//spu/utils:distributed",
    ],
)

py_test(
    name = "jax_compile_test",
    srcs = ["jax_compile_test.py"],
    deps = [
        ":jnp_testbase",
    ],
)
